﻿<%@ Page Language="c#" ContentType="text/html" ResponseEncoding="utf-8" Async="true" EnableEventValidation="false" MasterPageFile="~/administration/master_popup.master" Inherits="ACM.cmsarea08.Administration.Core.OptPageBase" %>
<%@ MasterType VirtualPath="~/administration/master_popup.master" %>
<asp:Content ID="PageBody" Runat="server" ContentPlaceHolderID="MasterBody">
<div id="option_popup">
<div class="popup_msgs">
Modifica Password



<script language="c#" runat="server">


		private string finduser = string.Empty;	
		private string email = string.Empty;
		private System.Data.DataRow userdata;
		
	
		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
		
	//		this.testLang.LanguageChanged += new itareanet.CMSAREA.ControlGallery.CambioHandler(this.LinguaCambia);
			
		}
		
		private void Page_Load(object sender, System.EventArgs e)
		{
						
			if(Request.QueryString["user"]!=null)
				finduser = Request.QueryString["user"].ToString();
			else
				Alert("Dati mancanti.",true);
			if(Request.QueryString["email"]!=null)
				email = Request.QueryString["email"].ToString();
			else
				Alert("Dati mancanti.",true);
			//lista_ruoli.SelectedIndex = selectedrole;
			
			
			if (!(Page.IsPostBack)) {
				//pass.ID += System.Guid.NewGuid().ToString();
				labname.Text = finduser;
			}
			
		}
	
	
	
		private void AcquireContent() {
			
	}
		private void Salva(object o, EventArgs e){
			
			string password = "";
			password = HttpUtility.HtmlEncode(pass.Value);
			if(password.Trim().Length <5 || password != ACM.cmsarea08.Function.TextClass.textclass.returnValidPassword(password)) {
				//Password non Valida
				Alert(rm.GetString("error_pass_user"),false);
					return;
			}
			string reso = ((ACM.cmsarea08.Provider.Itan_MembershipProvider)Membership.Provider).ResetPassword(finduser,password);
			if(ismail.Checked==true)
				ACM.cmsarea08.Function.TextClass.textclass.InviaEmailSimple(email,ACM.cmsarea08.mainconfiguration.MainConf.NoReplyEmailAddress,"Nuova Password - " + 
				ACM.cmsarea08.mainconfiguration.MainConf.NomePortale,
                                                   "<h1>La tua password &egrave; stata cambiata<br/><br/>Nuova password: \"" + password + "\"</h1>",true);
			if(reso.ToLower()=="ok")
				Alert("Password modificata con successo",true);
			else{
				Alert("Errore server. Riprova più tardi.",false);
			}
		}
		private void Alert(string error, bool close){
			this.Controls.Add(new LiteralControl("<script type=\"text/javascript\">alert('"+error+"');" +
				(close?"window.parent.closeModal();":"") + " </" + "script>"));
		
		
		}

	
</script>

<div style="display:block;">
<div style="float:left;">
   
		<span>Utente</span><br />
        <asp:Label ID="labname" runat="server"></asp:Label><br />
        <input type="text" ID="pass" runat="server" />
        <input type="button" onclick="CreaRandomPassword()" value="Random" />
        <br />
        <asp:CheckBox ID="ismail" runat="server" Text="Invia Mail"></asp:CheckBox>
        <br />
        <asp:Button ID="salva" Text="Salva" OnClick="Salva" runat="server"></asp:Button>
        
        
        <br />

			
</div></div>
	

      	<input type="hidden" id="templist_values" value="" runat="server" />
		
      
		
</div></div>

<script type="text/javascript" language="javascript">

function S4() {
    return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}

function CreaRandomPassword(){
       var ran = ((S4()+S4()).toLowerCase());
	   var pass = document.getElementById('<%= pass.ClientID %>');
	   
	   if(pass!=null){
	   		
			pass.value = ran;
		}
		
}




</script>
</asp:Content>
